package com.xunyu.shopping_manager_api.interceptor;

import cn.dev33.satoken.stp.StpUtil;
import com.xinyu.shopping_common.enums.CodeEnum;
import com.xinyu.shopping_common.exception.BusException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;


@Component
public class CheckLoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        //如果没有登录
        if(!StpUtil.isLogin()){
            throw new BusException(CodeEnum.NO_LOGIN_ERROR);
        }

        return true;
    }
}
